
package com.sample.library;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.content.res.Configuration;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Environment;
import android.provider.Settings.Secure;
import android.provider.Settings.System;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Base64;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.security.MessageDigest;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Calendar;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;

import javax.microedition.khronos.opengles.GL10;

import static android.content.Context.TELEPHONY_SERVICE;


@SuppressWarnings("ALL")
public class DeviceUtil {
    protected static final String LOG_TAG = DeviceUtil.class.getName();
    public static final String UNKNOW = "";
    public static final String MOBILE_NETWORK = "2G/3G";
    public static final String WIFI = "Wi-Fi";
    public static final int DEFAULT_TIMEZONE = 8;
    private static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";
    private static final String KEY_EMUI_VERSION_CODE = "ro.build.hw_emui_api_level";

    private static String sWifiMac;
    private static String sImei;
    private static String sMeid;
    private static String sImsi;


    public static String getImei(Context context) {
        if (!TextUtils.isEmpty(sImei)) {
            return sImei;
        } else {
            String deviceId = null;
            try {
                if (context != null) {
                    TelephonyManager manager = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);
                    if (manager != null && checkPermission(context, android.Manifest.permission.READ_PHONE_STATE)) {
                        deviceId = manager.getDeviceId();
                    }
                }
            } catch (Exception e) {
                Log.e("DeviceUtil", e.getMessage());
            }
            sImei = deviceId;
            return deviceId;
        }
    }


    public static String getAndroidId(Context context) {
        String androidId = null;
        if (context != null) {
            try {
                androidId = Secure.getString(context.getContentResolver(), "android_id");
            } catch (Exception e) {
                Log.e("DeviceUtil", e.getMessage());
            }
        }
        return androidId;
    }

    public static String getSerial() {
        if (VERSION.SDK_INT >= 9) {
            String serial = null;
            int sdkInt = VERSION.SDK_INT;
            if (sdkInt >= 26) {
                try {
                    Class clazz = Class.forName("android.os.Build");
                    Method method = clazz.getMethod("getSerial");
                    serial = (String) method.invoke(clazz);
                } catch (Throwable throwable) {
                    Log.e("DeviceUtil", throwable.getMessage());
                }
            } else {
                serial = Build.SERIAL;
            }
            return serial;
        } else {
            return null;
        }
    }


    private static boolean checkPermission(Context context, String permissions) {
        boolean isGranted = false;
        if (context == null) {
            return isGranted;
        } else {
            if (VERSION.SDK_INT >= 23) {
                try {
                    Class clazz = Class.forName("android.content.Context");
                    Method method = clazz.getMethod("checkSelfPermission", String.class);
                    int result = (Integer) method.invoke(context, permissions);
                    if (result == 0) {
                        isGranted = true;
                    } else {
                        isGranted = false;
                    }
                } catch (Throwable throwable) {
                    isGranted = false;
                    Log.e("DeviceUtil", throwable.getMessage());
                }
            } else {
                PackageManager packageManager = context.getPackageManager();
                if (packageManager.checkPermission(permissions, context.getPackageName()) == 0) {
                    isGranted = true;
                }
            }
            return isGranted;
        }
    }

    public static String[] getGPU(GL10 var0) {
        try {
            String[] var1 = new String[2];
            String var2 = var0.glGetString(7936);
            String var3 = var0.glGetString(7937);
            var1[0] = var2;
            var1[1] = var3;
            return var1;
        } catch (Throwable var4) {


            return new String[0];
        }
    }

    private static String getMacByJavaAPI() {
        try {

            Enumeration var0 = NetworkInterface.getNetworkInterfaces();

            NetworkInterface var1;
            do {
                if (!var0.hasMoreElements()) {
                    return null;
                }

                var1 = (NetworkInterface) var0.nextElement();
            } while (!"wlan0".equals(var1.getName()) && !"eth0".equals(var1.getName()));

            byte[] var2 = var1.getHardwareAddress();
            if (var2 != null && var2.length != 0) {
                StringBuilder var3 = new StringBuilder();
                byte[] var4 = var2;
                int var5 = var2.length;

                for (int var6 = 0; var6 < var5; ++var6) {
                    byte var7 = var4[var6];
                    var3.append(String.format("%02X:", var7));
                }

                if (var3.length() > 0) {
                    var3.deleteCharAt(var3.length() - 1);
                }

                return var3.toString().toLowerCase(Locale.getDefault());
            }

            return null;

        } catch (Throwable var8) {
        }

        return null;
    }

    private static String getMacShell() {
        try {

            String[] var0 = new String[]{"/sys/class/net/wlan0/address", "/sys/class/net/eth0/address", "/sys/devices/virtual/net/wlan0/address"};

            for (int var2 = 0; var2 < var0.length; ++var2) {
                try {
                    String var1 = reaMac(var0[var2]);
                    if (var1 != null) {
                        return var1;
                    }
                } catch (Throwable var4) {

                }
            }

        } catch (Throwable var5) {
        }

        return null;
    }

    private static String reaMac(String var0) {
        String var1 = null;

        try {
            FileReader var2 = new FileReader(var0);
            BufferedReader var3 = null;
            if (var2 != null) {
                try {
                    var3 = new BufferedReader(var2, 1024);
                    var1 = var3.readLine();
                } finally {
                    if (var2 != null) {
                        try {
                            var2.close();
                        } catch (Throwable var14) {
                        }
                    }

                    if (var3 != null) {
                        try {
                            var3.close();
                        } catch (Throwable var13) {
                        }
                    }

                }
            }
        } catch (Throwable var16) {
        }

        return var1;
    }

    public static String getCPU() {
        String var0 = null;
        FileReader var1 = null;
        BufferedReader var2 = null;

        try {
            var1 = new FileReader("/proc/cpuinfo");
            if (var1 != null) {
                try {
                    var2 = new BufferedReader(var1, 1024);
                    var0 = var2.readLine();
                    var2.close();
                    var1.close();
                } catch (Throwable var4) {
                }
            }
        } catch (FileNotFoundException var5) {
        }

        if (var0 != null) {
            int var3 = var0.indexOf(58) + 1;
            var0 = var0.substring(var3);
            return var0.trim();
        } else {
            return "";
        }
    }

    public static String getDeviceId(Context var0) {
        return getDeviceIdForGeneral(var0);
    }


    public static String getMCCMNC(Context var0) {
        try {
            if (var0 == null) {
                return null;
            }

            if (getImsi(var0) == null) {
                return null;
            }

            int var1 = var0.getResources().getConfiguration().mcc;
            int var2 = var0.getResources().getConfiguration().mnc;
            if (var1 != 0) {
                String var3 = String.valueOf(var2);
                if (var2 < 10) {
                    var3 = String.format("%02d", var2);
                }

                return var1 + var3;
            }
        } catch (Throwable var4) {
        }

        return null;
    }

    public static String getImsi(Context var0) {
        if (!TextUtils.isEmpty(sImsi)) {
            return sImsi;
        } else {
            String var1 = null;
            if (var0 == null) {
                return null;
            } else {
                TelephonyManager var2 = (TelephonyManager) var0.getSystemService("phone");

                try {
                    if (checkPermission(var0, "android.permission.READ_PHONE_STATE") && var2 != null) {
                        var1 = var2.getSubscriberId();
                    }
                } catch (Throwable var4) {
                }


                sImsi = var1;
                return sImsi;
            }
        }
    }

    public static String getMeid(Context var0) {
        String var1 = null;
        if (var0 == null) {
            return null;
        } else {
            TelephonyManager var2 = (TelephonyManager) var0.getSystemService("phone");
            if (var2 == null) {
                return null;
            } else {

                try {
                    if (checkPermission(var0, "android.permission.READ_PHONE_STATE") && var2 != null) {
                        if (VERSION.SDK_INT < 26) {
                            var1 = getIMEI(var0);
                        } else {
                            try {
                                var1 = meid(var0);
                                if (TextUtils.isEmpty(var1)) {
                                    var1 = getIMEI(var0);
                                }
                            } catch (Throwable var4) {
                            }
                        }
                    }
                } catch (Throwable var5) {
                }
            }

            return var1;

        }
    }

    private static String meid(Context var0) {
        if (TextUtils.isEmpty(sMeid)) {
            return sMeid;
        } else {
            String var1 = null;
            if (var0 == null) {
                return null;
            } else {
                try {
                    Class var2 = Class.forName("android.telephony.TelephonyManager");
                    Method var3 = var2.getMethod("getMeid");
                    Object var4 = var3.invoke((Object) null);
                    if (null != var4 && var4 instanceof String) {
                        var1 = (String) var4;
                    }
                } catch (Throwable var5) {

                }

                sMeid = var1;
                return sMeid;
            }
        }
    }

    public static String getSimICCID(Context var0) {
        String var1 = null;

        try {
            if (var0 != null && checkPermission(var0, "android.permission.READ_PHONE_STATE")) {
                TelephonyManager var2 = (TelephonyManager) var0.getSystemService("phone");
                if (var2 == null) {
                    return var1;
                }

                var1 = var2.getSimSerialNumber();
            }
        } catch (Throwable var3) {
        }


        return var1;
    }


    public static String getSecondSimIMEi(Context var0) {
        String var1 = null;
        if (var0 != null && VERSION.SDK_INT >= 23 && checkPermission(var0, "android.permission.READ_PHONE_STATE")) {
            try {
                TelephonyManager var2 = (TelephonyManager) var0.getSystemService("phone");
                if (var2 == null) {
                    return var1;
                }

                Class var3 = var2.getClass();
                Method var4 = var3.getMethod("getPhoneCount");
                int var5 = (Integer) var4.invoke(var2);
                if (var5 == 2) {
                    Method var6 = var3.getMethod("getDeviceId", Integer.TYPE);
                    var1 = (String) var6.invoke(var2, 2);
                }
            } catch (Throwable var7) {
            }
        }

        return var1;
    }

    public static String getRegisteredOperator(Context var0) {
        if (var0 == null) {
            return null;
        } else {
            String var1 = null;

            try {
                TelephonyManager var2 = (TelephonyManager) var0.getSystemService("phone");
                if (checkPermission(var0, "android.permission.READ_PHONE_STATE") && var2 != null) {
                    var1 = var2.getNetworkOperator();
                }
            } catch (Throwable var3) {
            }

            return var1;
        }
    }

    public static String getNetworkOperatorName(Context var0) {
        if (var0 == null) {
            return "";
        } else {
            try {
                TelephonyManager var1 = (TelephonyManager) var0.getSystemService("phone");
                if (checkPermission(var0, "android.permission.READ_PHONE_STATE") && var1 != null) {
                    return var1.getNetworkOperatorName();
                }
            } catch (Throwable var2) {
            }

            return "";
        }
    }

    public static String getDisplayResolution(Context var0) {
        if (var0 == null) {
            return "";
        } else {
            try {
                DisplayMetrics var1 = new DisplayMetrics();
                WindowManager var2 = (WindowManager) ((WindowManager) var0.getSystemService("window"));
                if (var2 != null) {
                    var2.getDefaultDisplay().getMetrics(var1);
                    int var3 = var1.widthPixels;
                    int var4 = var1.heightPixels;
                    String var5 = var4 + "*" + var3;
                    return var5;
                } else {
                    return "";
                }
            } catch (Throwable var6) {
                return "";
            }
        }
    }

    public static String[] getNetworkAccessMode(Context var0) {
        String[] var1 = new String[]{"", ""};
        if (var0 == null) {
            return var1;
        } else {
            try {
                if (!checkPermission(var0, "android.permission.ACCESS_NETWORK_STATE")) {
                    var1[0] = "";
                    return var1;
                }

                ConnectivityManager var2 = (ConnectivityManager) var0.getSystemService("connectivity");
                if (var2 == null) {
                    var1[0] = "";
                    return var1;
                }

                NetworkInfo var3 = var2.getNetworkInfo(1);
                if (var3 != null && var3.getState() == State.CONNECTED) {
                    var1[0] = "Wi-Fi";
                    return var1;
                }

                NetworkInfo var4 = var2.getNetworkInfo(0);
                if (var4 != null && var4.getState() == State.CONNECTED) {
                    var1[0] = "2G/3G";
                    var1[1] = var4.getSubtypeName();
                    return var1;
                }
            } catch (Throwable var5) {
            }

            return var1;
        }
    }

    public static String getIPAddress(Context var0) {
        String var1 = null;
        String var2 = null;

        try {
            Enumeration var3 = NetworkInterface.getNetworkInterfaces();
            Iterator var4 = Collections.list(var3).iterator();

            while (var4.hasNext()) {
                NetworkInterface var5 = (NetworkInterface) var4.next();
                Enumeration var6 = var5.getInetAddresses();
                Iterator var7 = Collections.list(var6).iterator();

                while (var7.hasNext()) {
                    InetAddress var8 = (InetAddress) var7.next();
                    if (!var8.isLoopbackAddress() && var8 instanceof Inet4Address && !var5.getDisplayName().contains("dummy") && var1 == null) {
                        var1 = var8.getHostAddress();
                    }

                    if (!var8.isLoopbackAddress() && var8 instanceof Inet6Address && !var5.getDisplayName().contains("dummy") && var2 == null) {
                        var2 = var8.getHostAddress();
                    }
                }
            }
        } catch (SocketException var9) {
            var1 = "SocketException";
        }

        if (var1 != null) {
            return var1;
        } else {
            var1 = var2;
            if (var2 == null) {
                var1 = "null";
            }

            return var1;
        }
    }

    public static int getNetworkType(Context var0) {
        int var1 = 0;

        try {
            TelephonyManager var2 = (TelephonyManager) var0.getSystemService("phone");
            if (checkPermission(var0, "android.permission.READ_PHONE_STATE")) {
                var1 = var2.getNetworkType();
            }
        } catch (Exception var3) {
            var1 = -100;
        }

        return var1;
    }

    public static boolean isWiFiAvailable(Context var0) {
        return var0 == null ? false : "Wi-Fi".equals(getNetworkAccessMode(var0)[0]);
    }

    public static boolean isOnline(Context var0) {
        if (var0 == null) {
            return false;
        } else {
            try {
                if (checkPermission(var0, "android.permission.ACCESS_NETWORK_STATE")) {
                    ConnectivityManager var1 = (ConnectivityManager) var0.getSystemService("connectivity");
                    if (var1 != null) {
                        NetworkInfo var2 = var1.getActiveNetworkInfo();
                        if (var2 != null) {
                            return var2.isConnectedOrConnecting();
                        }
                    }
                }
            } catch (Throwable var3) {
            }

            return false;
        }
    }

    public static int getTimeZone(Context var0) {
        if (var0 == null) {
            return 8;
        } else {
            try {
                Locale var1 = getLocale(var0);
                Calendar var2 = Calendar.getInstance(var1);
                if (var2 != null) {
                    return var2.getTimeZone().getRawOffset() / 3600000;
                }
            } catch (Throwable var3) {
            }

            return 8;
        }
    }

    public static boolean isChineseAera(Context var0) {
        if (var0 == null) {
            return false;
        } else {
            try {
                String var1 = imprintProperty(var0, "country", "");
                if (!TextUtils.isEmpty(var1)) {
                    if (var1.equals("cn")) {
                        return true;
                    }
                    return false;
                }

                if (getImsi(var0) == null) {
                    var1 = getLocaleInfo(var0)[0];
                    if (!TextUtils.isEmpty(var1) && var1.equalsIgnoreCase("cn")) {
                        return true;
                    }
                } else {
                    int var2 = var0.getResources().getConfiguration().mcc;
                    if (var2 == 460 || var2 == 461) {
                        return true;
                    }

                    if (var2 == 0) {
                        var1 = getLocaleInfo(var0)[0];
                        if (!TextUtils.isEmpty(var1) && var1.equalsIgnoreCase("cn")) {
                            return true;
                        }
                    }
                }
            } catch (Throwable var3) {
            }

            return false;
        }
    }

    public static String[] getLocaleInfo(Context var0) {
        String[] var1 = new String[]{"Unknown", "Unknown"};
        if (var0 == null) {
            return var1;
        } else {
            try {
                Locale var2 = getLocale(var0);
                if (var2 != null) {
                    var1[0] = var2.getCountry();
                    var1[1] = var2.getLanguage();
                }

                if (TextUtils.isEmpty(var1[0])) {
                    var1[0] = "Unknown";
                }

                if (TextUtils.isEmpty(var1[1])) {
                    var1[1] = "Unknown";
                }

                return var1;
            } catch (Throwable var3) {
                return var1;
            }
        }
    }

    private static Locale getLocale(Context var0) {
        Locale var1 = null;
        if (var0 == null) {
            var1 = Locale.getDefault();
            return var1;
        } else {
            try {
                Configuration var2 = new Configuration();
                var2.setToDefaults();
                System.getConfiguration(var0.getContentResolver(), var2);
                if (var2 != null) {
                    var1 = var2.locale;
                }
            } catch (Throwable var3) {
            }

            if (var1 == null) {
                var1 = Locale.getDefault();
            }

            return var1;
        }
    }

    public static String getMac(Context var0) {
        if (!TextUtils.isEmpty(sWifiMac)) {
            return sWifiMac;
        } else {
            String var1 = "";
            if (var0 == null) {
                return var1;
            }

            if (VERSION.SDK_INT < 23) {
                var1 = getMacBySystemInterface(var0);
            } else if (VERSION.SDK_INT == 23) {
                var1 = getMacByJavaAPI();
                if (TextUtils.isEmpty(var1)) {
//                        if (AnalyticsConstants.CHECK_DEVICE) {
                    var1 = getMacShell();
//                        } else {
//                            var1 = getMacBySystemInterface(var0);
//                        }
                }
            } else {
                var1 = getMacByJavaAPI();
                if (TextUtils.isEmpty(var1)) {
                    var1 = getMacBySystemInterface(var0);
                }
            }


            sWifiMac = var1;
            return sWifiMac;
        }
    }

    private static String getMacBySystemInterface(Context var0) {
        if (var0 == null) {
            return "";
        } else {
            try {

                WifiManager var1 = (WifiManager) var0.getSystemService("wifi");
                if (checkPermission(var0, "android.permission.ACCESS_WIFI_STATE")) {
                    if (var1 != null) {
                        WifiInfo var2 = var1.getConnectionInfo();
                        return var2.getMacAddress();
                    } else {
                        return "";
                    }
                } else {

                    return "";
                }

            } catch (Throwable var3) {


                return "";
            }
        }
    }

    public static int[] getResolutionArray(Context var0) {
        if (var0 == null) {
            return null;
        } else {
            try {
                DisplayMetrics var1 = new DisplayMetrics();
                WindowManager var2 = (WindowManager) ((WindowManager) var0.getSystemService("window"));
                if (var2 == null) {
                    return null;
                } else {
                    var2.getDefaultDisplay().getMetrics(var1);
                    int var3 = -1;
                    int var4 = -1;
                    if ((var0.getApplicationInfo().flags & 8192) == 0) {
                        var3 = reflectMetrics(var1, "noncompatWidthPixels");
                        var4 = reflectMetrics(var1, "noncompatHeightPixels");
                    }

                    if (var3 == -1 || var4 == -1) {
                        var3 = var1.widthPixels;
                        var4 = var1.heightPixels;
                    }

                    int[] var5 = new int[2];
                    if (var3 > var4) {
                        var5[0] = var4;
                        var5[1] = var3;
                    } else {
                        var5[0] = var3;
                        var5[1] = var4;
                    }

                    return var5;
                }
            } catch (Throwable var6) {

                return null;
            }
        }
    }

    private static int reflectMetrics(Object var0, String var1) {
        try {
            Field var2 = DisplayMetrics.class.getDeclaredField(var1);
            var2.setAccessible(true);
            return var2.getInt(var0);
        } catch (Throwable var3) {
            return -1;
        }
    }

    public static String getPackageName(Context var0) {
        return var0 == null ? null : var0.getPackageName();
    }

    public static String getAppSHA1Key(Context var0) {
        X509Certificate var1 = null;
        String var2 = null;

        try {
            PackageManager var3 = var0.getPackageManager();
            byte var4 = 64;
            PackageInfo var5 = var3.getPackageInfo(getPackageName(var0), var4);
            Signature[] var6 = var5.signatures;
            byte[] var7 = var6[0].toByteArray();
            ByteArrayInputStream var8 = new ByteArrayInputStream(var7);
            CertificateFactory var9 = null;
            var9 = CertificateFactory.getInstance("X509");
            var1 = (X509Certificate) var9.generateCertificate(var8);
            MessageDigest var10 = MessageDigest.getInstance("SHA1");
            byte[] var11 = var10.digest(var1.getEncoded());
            var2 = byte2HexFormatted(var11);
        } catch (Exception var12) {
        }

        return var2;
    }

    public static String getAppHashKey(Context var0) {
        try {
            PackageManager var1 = var0.getPackageManager();
            byte var2 = 64;
            PackageInfo var3 = var1.getPackageInfo(getPackageName(var0), var2);
            Signature[] var4 = var3.signatures;
            int var5 = var4.length;
            byte var6 = 0;
            if (var6 < var5) {
                Signature var7 = var4[var6];
                MessageDigest var8 = MessageDigest.getInstance("SHA");
                var8.update(var7.toByteArray());
                return Base64.encodeToString(var8.digest(), 0).trim();
            }
        } catch (Throwable var9) {
        }

        return null;
    }

    public static String getAppMD5Signature(Context var0) {
        String var1 = null;
        if (var0 == null) {
            return var1;
        } else {
            try {
                PackageManager var2 = var0.getPackageManager();
                byte var3 = 64;
                PackageInfo var4 = var2.getPackageInfo(getPackageName(var0), var3);
                Signature[] var5 = var4.signatures;
                byte[] var6 = var5[0].toByteArray();
                ByteArrayInputStream var7 = new ByteArrayInputStream(var6);
                CertificateFactory var8 = CertificateFactory.getInstance("X509");
                X509Certificate var9 = (X509Certificate) var8.generateCertificate(var7);
                MessageDigest var10 = MessageDigest.getInstance("MD5");
                byte[] var11 = var10.digest(var9.getEncoded());
                var1 = byte2HexFormatted(var11);
            } catch (Throwable var12) {
            }

            return var1;
        }
    }

    private static String byte2HexFormatted(byte[] var0) {
        StringBuilder var1 = new StringBuilder(var0.length * 2);

        for (int var2 = 0; var2 < var0.length; ++var2) {
            String var3 = Integer.toHexString(var0[var2]);
            int var4 = var3.length();
            if (var4 == 1) {
                var3 = "0" + var3;
            }

            if (var4 > 2) {
                var3 = var3.substring(var4 - 2, var4);
            }

            var1.append(var3.toUpperCase(Locale.getDefault()));
            if (var2 < var0.length - 1) {
                var1.append(':');
            }
        }

        return var1.toString();
    }

    public static String getApplicationLable(Context var0) {
        return var0 == null ? "" : var0.getPackageManager().getApplicationLabel(var0.getApplicationInfo()).toString();
    }

    public static String getAppName(Context var0) {
        String var1 = null;
        if (var0 == null) {
            return var1;
        } else {
            try {
                PackageInfo var2 = var0.getPackageManager().getPackageInfo(var0.getPackageName(), 0);
                var1 = var2.applicationInfo.loadLabel(var0.getPackageManager()).toString();
            } catch (Throwable var3) {

            }

            return var1;
        }
    }


    public static String getDeviceIdForGeneral(Context var0) {
        String var1 = "";
        if (var0 == null) {
            return var1;
        } else {
            try {
                if (VERSION.SDK_INT < 23) {
                    var1 = getIMEI(var0);
                    if (TextUtils.isEmpty(var1)) {

                        var1 = getMacBySystemInterface(var0);
                        if (TextUtils.isEmpty(var1)) {

                            var1 = Secure.getString(var0.getContentResolver(), "android_id");

                            if (TextUtils.isEmpty(var1)) {
                                var1 = getSerialNo();
                            }
                        }
                    }
                } else if (VERSION.SDK_INT == 23) {
                    var1 = getIMEI(var0);
                    if (TextUtils.isEmpty(var1)) {
                        var1 = getMacByJavaAPI();
                        if (TextUtils.isEmpty(var1)) {
                            var1 = getMacShell();
                        }

                        if (TextUtils.isEmpty(var1)) {

                            var1 = Secure.getString(var0.getContentResolver(), "android_id");
                        }

                        if (TextUtils.isEmpty(var1)) {
                            var1 = getSerialNo();
                        }

                    }
                } else if (VERSION.SDK_INT >= 29) {
                    var1 = getOaid(var0);
                    if (TextUtils.isEmpty(var1)) {
                        var1 = getIdfa(var0);
                        if (TextUtils.isEmpty(var1)) {
                            var1 = getAndroidId(var0);
                            if (TextUtils.isEmpty(var1)) {
                                var1 = getSerialNo();
                                if (TextUtils.isEmpty(var1)) {
                                    var1 = getMacByJavaAPI();
                                    if (TextUtils.isEmpty(var1)) {
                                        var1 = getMacBySystemInterface(var0);
                                    }
                                }
                            }
                        }
                    }
                } else {
                    var1 = getIMEI(var0);
                    if (TextUtils.isEmpty(var1)) {
                        var1 = getSerialNo();
                        if (TextUtils.isEmpty(var1)) {
                            var1 = Secure.getString(var0.getContentResolver(), "android_id");
                            if (TextUtils.isEmpty(var1)) {
                                var1 = getMacByJavaAPI();
                                if (TextUtils.isEmpty(var1)) {
                                    var1 = getMacBySystemInterface(var0);
                                }
                            }
                        }
                    }
                }
            } catch (Throwable var3) {
            }
            if (TextUtils.isEmpty(var1)) {
                var1 = getGUID(var0);
            }
            return var1;
        }
    }


    public static String getGUID(Context context) {
        SharedPreferences preferences = context.getSharedPreferences("GUID", Context.MODE_PRIVATE);
        String uuid = preferences.getString("uuid", "");
        if (TextUtils.isEmpty(uuid)) {
            uuid = UUID.randomUUID().toString();
            preferences.edit().putString("uuid", uuid).apply();
        }
        return uuid;
    }

    public static String getOaid(Context var0) {
        SharedPreferences sharedPreferences = var0.getSharedPreferences("oaid", Context.MODE_PRIVATE);
        return sharedPreferences.getString("OAID", "");
    }

    private static String getIdfa(Context var0) {
        String var1 = "";
        try {
            var1 = IDFA.a(var0);
        } catch (Throwable var3) {
        }
        return var1;
    }

    private static String getIMEI(Context var0) {
        if (!TextUtils.isEmpty(sImei)) {
            return sImei;
        } else {
            String var1 = "";
            if (var0 == null) {
                return var1;
            }

            TelephonyManager var2 = (TelephonyManager) var0.getSystemService("phone");
            if (var2 != null) {
                try {
                    if (checkPermission(var0, "android.permission.READ_PHONE_STATE")) {
                        var1 = var2.getDeviceId();
                    }
                } catch (Throwable var4) {


                }
            }

            sImei = var1;
            return sImei;
        }
    }

    private static String getSerialNo() {
        String var0 = "";

        if (VERSION.SDK_INT >= 26) {
            try {
                Class var1 = Class.forName("android.os.Build");
                Method var2 = var1.getMethod("getSerial");
                var0 = (String) var2.invoke(var1);
            } catch (Throwable var3) {
            }
        } else {
            var0 = Build.SERIAL;

        }
        return var0;
    }

    public static String getSubOSName(Context var0) {
        String var1 = null;
        Properties var2 = getBuildProp();

        try {
            var1 = var2.getProperty("ro.miui.ui.version.name");
            if (TextUtils.isEmpty(var1)) {
                if (isFlyMe()) {
                    var1 = "Flyme";
                } else if (isEmui(var2)) {
                    var1 = "Emui";
                } else if (!TextUtils.isEmpty(getYunOSVersion(var2))) {
                    var1 = "YunOS";
                }
            } else {
                var1 = "MIUI";
            }
        } catch (Throwable var4) {
            var1 = null;
        }

        return var1;
    }

    public static String getSubOSVersion(Context var0) {
        String var1 = null;
        Properties var2 = getBuildProp();

        try {
            var1 = var2.getProperty("ro.miui.ui.version.name");
            if (TextUtils.isEmpty(var1)) {
                if (isFlyMe()) {
                    try {
                        var1 = getFlymeVersion(var2);
                    } catch (Throwable var6) {
                    }
                } else if (isEmui(var2)) {
                    try {
                        var1 = getEmuiVersion(var2);
                    } catch (Throwable var5) {
                    }
                } else {
                    try {
                        var1 = getYunOSVersion(var2);
                    } catch (Throwable var4) {
                    }
                }
            }
        } catch (Throwable var7) {
            var1 = null;
        }

        return var1;
    }

    private static String getYunOSVersion(Properties var0) {
        try {
            String var1 = var0.getProperty("ro.yunos.version");
            if (!TextUtils.isEmpty(var1)) {
                return var1;
            }
        } catch (Throwable var2) {
        }

        return null;
    }

    private static String getFlymeVersion(Properties var0) {
        try {
            String var1 = var0.getProperty("ro.build.display.id").toLowerCase(Locale.getDefault());
            if (var1.contains("flyme os")) {
                return var1.split(" ")[2];
            }
        } catch (Throwable var2) {
        }

        return null;
    }

    private static String getEmuiVersion(Properties var0) {
        String var1 = null;

        try {
            var1 = var0.getProperty("ro.build.hw_emui_api_level", (String) null);
        } catch (Exception var3) {
        }

        return var1;
    }

    private static Properties getBuildProp() {
        Properties var0 = new Properties();
        FileInputStream var1 = null;

        try {
            var1 = new FileInputStream(new File(Environment.getRootDirectory(), "build.prop"));
            var0.load(var1);
        } catch (Throwable var11) {
        } finally {
            if (var1 != null) {
                try {
                    var1.close();
                } catch (Throwable var10) {
                }
            }

        }

        return var0;
    }

    private static boolean isFlyMe() {
        try {
            Build.class.getMethod("hasSmartBar");
            return true;
        } catch (Throwable var1) {
            return false;
        }
    }

    private static boolean isEmui(Properties var0) {
        try {
            String var1 = var0.getProperty("ro.build.hw_emui_api_level", (String) null);
            return var1 != null;
        } catch (Exception var2) {
            return false;
        }
    }

    public static String getDeviceType(Context var0) {
        String var1 = "Phone";

        try {
            if (var0 == null) {
                return var1;
            }

            boolean var2 = (var0.getResources().getConfiguration().screenLayout & 15) >= 3;
            if (var2) {
                var1 = "Tablet";
            } else {
                var1 = "Phone";
            }
        } catch (Throwable var3) {
        }

        return var1;
    }


    public static Activity getGlobleActivity(Context var0) {
        Activity var1 = null;

        try {
            Class var2 = Class.forName("android.app.ActivityThread");
            Object var3 = var2.getMethod("currentActivityThread").invoke((Object) null);
            Field var4 = var2.getDeclaredField("mActivities");
            var4.setAccessible(true);
            Map var5 = (Map) var4.get(var3);
            Iterator var6 = var5.values().iterator();

            while (var6.hasNext()) {
                Object var7 = var6.next();
                Class var8 = var7.getClass();
                Field var9 = var8.getDeclaredField("paused");
                var9.setAccessible(true);
                if (!var9.getBoolean(var7)) {
                    Field var10 = var8.getDeclaredField("activity");
                    var10.setAccessible(true);
                    var1 = (Activity) var10.get(var7);
                }
            }
        } catch (Throwable var11) {
        }

        return var1;
    }

    public static String imprintProperty(Context var0, String var1, String var2) {
        return var2;
    }

    static {
        sWifiMac = "";
        sImei = "";
        sMeid = "";
        sImsi = "";
    }

}
